package com.heima.controller;

import com.heima.pojo.dto.SkuDto;
import com.heima.pojo.dto.SkuSearchDto;
import com.heima.pojo.vo.SkuSearchVo;
import com.heima.service.SkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/vm-service/sku")
@Api(tags = "商品相关接口")
@Slf4j
@RequiredArgsConstructor
public class SkuController {
    private final SkuService skuService;

    @PostMapping
    @ApiOperation("新增商品")
    public boolean addSku(@RequestBody SkuDto skuDto){
        skuService.addSku(skuDto);
        return true;
    }

    @GetMapping("/search")
    @ApiOperation("商品搜索+分页")
    public SkuSearchVo pageQuery(SkuSearchDto skuSearchDto){
        return skuService.pageQuery(skuSearchDto);
    }

    @PutMapping("/{skuId}")
    @ApiOperation("修改商品")
    public boolean updateSku(@PathVariable String skuId ,@RequestBody SkuDto skuDto){
        skuService.update(skuId,skuDto);
        return true;
    }

    @PostMapping("/upload")
    @ApiOperation("商品数据导入")
    public void fileUpload(@RequestBody MultipartFile fileName){
        //TODO 商品数据导入
    }
}
